//
//  AWFileChatMessage.m
//  AtWork2
//
//  Created by lucas on 15/5/28.
//  Copyright (c) 2015年 Foreveross. All rights reserved.
//

#import "AWFileChatMessage.h"

@implementation AWFileChatMessage

+ (instancetype)fileChatMessageWithFrom:(NSString *)from
                                     to:(NSString *)to
                                   size:(NSUInteger)size
                                   name:(NSString *)name
                           chatDestType:(AWChatDestType)chatDestType {
    return [[self alloc] initWithFrom:from to:to size:size name:name chatDestType:chatDestType];
}

- (instancetype)initWithFrom:(NSString *)from
                          to:(NSString *)to
                        size:(NSUInteger)size
                        name:(NSString *)name
                chatDestType:(AWChatDestType)chatDestType {
    if (self = [super initWithFrom:from to:to messageType:AWMessageTypeChat]) {
        self.size = size;
        self.name = name;
        self.chatMessageType = AWChatMessageTypeFile;
        self.chatDestType = chatDestType;
    }
    return self;
}

- (instancetype)initWithFrom:(NSString *)from
                          to:(NSString *)to
                        size:(NSUInteger)size
                        name:(NSString *)name {
    if (self = [super initWithFrom:from to:to messageType:AWMessageTypeServeNo]) {
        self.size = size;
        self.name = name;
        self.chatMessageType = AWChatMessageTypeFile;
    }
    return self;
}

+ (instancetype)initServceAppWithFrom:(NSString *)from
                          to:(NSString *)to
                        size:(NSUInteger)size
                        name:(NSString *)name {
    return [[self alloc] initWithFrom:from to:to size:size name:name];
}

#pragma mark - Getter Settter Methods

- (void)setSize:(NSUInteger)size {
    [self bodyWithKey:AWMessageKSize value:@(size)];
}

- (NSUInteger)size {
    return [[self bodyValueForKey:AWMessageKSize] unsignedIntegerValue];
}

- (void)setName:(NSString *)name {
    [self bodyWithKey:AWMessageKName value:name];
}

- (NSString *)name {
    return [self bodyValueForKey:AWMessageKName];
}

- (void)setMediaId:(NSString *)mediaId {
    [self bodyWithKey:AWMessageKMediaId value:mediaId];
}

- (NSString *)mediaId {
    return [self bodyValueForKey:AWMessageKMediaId];
}

- (void)setExpireTime:(UInt64)expireTime {
    [self bodyWithKey:AWMessageKExpireTime value:@(expireTime)];
}

- (UInt64)expireTime {
    return [[self bodyValueForKey:AWMessageKExpireTime] unsignedLongLongValue];
}

- (void)setThumbnail:(NSData *)thumbnail {
    [self bodyWithKey:AWMessageKThumbnail value:base64WithData(thumbnail)];
}

- (NSData *)thumbnail {
    if ([self bodyValueForKey:AWMessageKThumbnail]) {
        return base64WithString([self bodyValueForKey:AWMessageKThumbnail]);
    }
    return [NSData data];
}

- (NSString *)searchableContent {
    return self.name;
}

- (void)setFileStatus:(AWFileChatMessageStatus)fileStatus {
    [self bodyWithKey:AWMessageKFileSatus value:@(fileStatus)];
}

- (AWFileChatMessageStatus)fileStatus {
    NSUInteger status = [[self bodyValueForKey:AWMessageKFileSatus] unsignedIntegerValue];
    return (AWFileChatMessageStatus)status;
}

- (void)setPath:(NSString *)path {
    [self bodyWithKey:AWMessageKPath value:path];
}

- (NSString *)path {
    return [self bodyValueForKey:AWMessageKPath];
}

- (void)setProgress:(float)progress{
    [self bodyWithKey:AWMessageKProgress value:@(progress)];
}
- (float)progress{
    return [[self bodyValueForKey:AWMessageKProgress] floatValue];
}

- (NSString *)fileStatusDescription {
    switch (self.fileStatus) {
        case AWFileChatMessageStatusSenderSent:
            return AWMessageKFileStatusSenderSent;
        case AWFileChatMessageStatusSenderSending:
            return AWMessageKFileStatusSenderSending;
        case AWFileChatMessageStatusSenderFault:
            return AWMessageKFileStatusSenderFault;
        case AWFileChatMessageStatusReceiverDownloaded:
            return AWMessageKFileStatusReceiverDownloaded;
        case AWFileChatMessageStatusReceiverUnDownloaded:
            return AWMessageKFileStatusReceiverUnDownloaded;
        case AWFileChatMessageStatusReceiverDownloading:
            return AWMessageKFileStatusReceiverDownloading;
        case AWFileChatMessageStatusReceiverInvalid:
            return AWMessageKFileStatusReceiverInvalid;
    }
}

@end
